package io.bdmc.common.utils;

import java.math.BigDecimal;
import java.util.List;

public class LatLngUtil {

    public static Boolean pnpoly(Integer nvert,BigDecimal[] vertx,BigDecimal[] verty, BigDecimal testx, BigDecimal testy)
    {
        int i, j= 0;
        Boolean c = false;
        for (i = 0, j = nvert - 1; i < nvert; j = i++)
        {
            if (((verty[i].compareTo(testy) >0 ) != (verty[j].compareTo(testy) >0 )) &&
             (testx.compareTo((vertx[j].subtract(vertx[i])).multiply(testy.subtract(verty[i]) ).divide(verty[j].subtract( verty[i])).add(vertx[i]))>0))
                c = !c;
        }
        return c;
    }

    static Boolean pnpoly1(Integer nvert,float[] vertx,float[] verty, float testx, float testy)
    {
        Integer i, j= 0;
        Boolean c = false;
        for (i = 0, j = nvert - 1; i < nvert; j = i++)
        {
            if (((verty[i] > testy) != (verty[j] > testy)) &&
             (testx < (vertx[j] - vertx[i]) * (testy - verty[i]) / (verty[j] - verty[i]) + vertx[i]))
                c = !c;
        }
        return c;
    }
}